﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using QLZJFurnitureSCM.Model;
using QLZJFurnitureSCM.DAL;
using System.Data;

namespace QLZJFurnitureSCM.BLL
{
    public class ProductService
    {
        private IBaseDAO<Product> baseDAO = new ProductDAO();
        private IProductDAO productDAO = new ProductDAO();

        public List<Product> ReadAll()
        {
            return baseDAO.ReadAll();
        }

        public Product InsertProduct(Product product)
        {
            return baseDAO.Create(product);
        }

        public DataTable ReadInDataTableByProductType(int productType)
        {
            return productDAO.ReadInDataTableByProductType(productType);
        }

        public bool CheckExistProductsByProductName(Product product)
        {
            return productDAO.CheckExistProductsByProductName(product);
        }

        public List<Product> FindProductsByProductType(int productType)
        {
            return productDAO.FindProductsByProductType(productType);
        }

        public DataTable ReadInDataTable(bool descSort)
        {
            return productDAO.ReadInDataTable(descSort);
        }

        public bool UpdateProductPriceCount(Product product)
        {
            return baseDAO.Update(product);
        }

        public bool UpdateProduct(Product product)
        {
            return productDAO.UpdateProduct(product);
        }

        public bool UpdateProductCount(Product product)
        {
            return productDAO.UpdateProductCount(product);
        }

        public bool UpdateProductCountBatch(List<Product> lstProduct)
        {
            foreach(Product product in lstProduct)
            {
                if (!UpdateProductCount(product))
                    return false;
            }
            return true;
        }

        public bool DeleteProduct(Product product)
        {
            return productDAO.DeleteProduct(product);
        }

        public bool UpdateDataTable(DataTable dt)
        {
            return productDAO.UpdateDataTable(dt);
        }
    }
}
